<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加管理员</title>
    <link rel="stylesheet" th:href="@{/src/css/layui.css}">
</head>
<body>
<form class="layui-form" style="width: 80%;" id="aaf">
    <div class="layui-form-item">
        <label class="layui-form-label">登录名</label>
        <div class="layui-input-block">
            <input type="text" id="username" class="layui-input"
                   lay-verify="required" placeholder="请输入登陆名" name="username" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="password" id="password" class="layui-input"
                   lay-verify="pass" placeholder="请输入密码" name="password" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-block">
            <input type="password" class="layui-input"
                   lay-verify="repass" placeholder="请输入确认密码" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="fullname" class="layui-input"
                   lay-verify="required" placeholder="请输入姓名" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="text" id="eMail" name="email" class="layui-input"
                   lay-verify="email" placeholder="请输入邮箱" value="">
           <!-- <label>（<span style="color: red">*</span>找回密码必须！）</label>-->
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="1" title="男" checked>
            <input type="radio" name="sex" value="0" title="女"> <input
                type="radio" name="sex" value="2" title="保密">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">出生日期</label>
        <div class="layui-input-block">
            <input type="text" id="birthday" class="layui-input"
                   name="birthday" lay-verify="required" autocomplete="off" placeholder="请输入出生日期">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">地址</label>
        <div class="layui-input-block">
            <input type="text" name="address" class="layui-input" lay-verify="required"
                   placeholder="请输入地址" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-block">
            <input type="text" name="phone" class="layui-input"
                   lay-verify="phone" placeholder="请输入手机号" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分配角色</label>
        <div class="layui-input-block">
            <select name="roleId">
                <option value="">请选择</option>
                <option th:each="r:${roles}" th:value="${r.roleId}">[[${r.roleName}]]</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="addAdmin">立即提交</button>
        </div>
    </div>
</form>
<script th:src="@{/src/layui.js}"></script>

<script>
        layui.use(['form','jquery','layer','laydate'],function () {
            var form = layui.form,
                $ = layui.jquery,
                layer = layui.layer,
            laydate = layui.laydate;

            laydate.render({
                elem:'#birthday',
                maxDate:'new Date()',
                trigger:'click'
            });

            //参数data就是表单中的数据
            form.on('submit(addAdmin)',function (data) {

                $.ajax({
                    url:'/admin/saveAdmin',
                    data:data.field,
                    dataType:'json',
                    type:'post',
                    success:function(result){
                        if(result.code == 200){
                            layer.msg('添加成功',{icon:1,time:1000},function () {
                                top.layer.closeAll("iframe");//关闭窗口
                               parent.location.reload();//从新加载数据
                            })
                        }else{
                            layer.msg(result.message,{icon:5});
                        }
                    }
                })
                return false;
            })

        });

</script>
</body>
</html>